package info.sean.main;

import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON;
import info.sean.util.DateUtil;
import info.sean.util.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.time.Duration;
import java.util.*;

import static org.apache.commons.lang3.time.DateUtils.truncate;

public class TestList {

    public static final String  REG_MATCH = "[]";
    @Test
    public void  testList(){


        ArrayList<String> gscBiddingNoList = new ArrayList<>();
        ArrayList<String> accBiddingNoList = new ArrayList<>();
        gscBiddingNoList.add("1");
        gscBiddingNoList.add("2");
        gscBiddingNoList.add("sean");
        accBiddingNoList.add("4");
        accBiddingNoList.add("7");
        accBiddingNoList.add("lan");
        System.out.println("arrayList"+gscBiddingNoList);
        System.out.println("objects"+accBiddingNoList);

        String join = StringUtils.join(accBiddingNoList, REG_MATCH);
        System.out.println("去掉集合的两边【】，然后再用此定义的分隔符进行连接并且分隔符可以为null:"+join);


        List<String> biddingNoList = null;
        List<String> finalBiddingNoList = new ArrayList<>();
        if (gscBiddingNoList != null){
            gscBiddingNoList.stream().forEach(gscBiddingNoLists -> {
                finalBiddingNoList.add(gscBiddingNoLists);
            });
        }
        if (accBiddingNoList != null){
            accBiddingNoList.stream().forEach(accBiddingNoLists -> {
                finalBiddingNoList.add(accBiddingNoLists);
            });
        }
        biddingNoList = finalBiddingNoList;
         biddingNoList.stream().forEach(biddingNo->{
             System.out.println("biddingNo::_"+biddingNo);
         });




    }



    @Test
    public void testDateUtils(){


        Date date = new Date();

        Date startOfDay = DateUtils.getStartOfDay(date);
        System.out.println(startOfDay);

        System.out.println("---------------");

        Date endOfDay = DateUtils.getEndOfDay(date);
        System.out.println(endOfDay);

    }



    public static void main(String[] args) {


        System.out.println("时间为："+new Date());

        Date add = add(new Date(), Calendar.DAY_OF_MONTH, -1);
        System.out.println("时间为："+ add);


    }


    public static Date add(Date date, int field, int amount) {
        if (date == null) {
            date = new Date();
        }

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(field, amount);

        return cal.getTime();
    }







}
class  TestDate{

    private   static  final  List<Integer> excludeOccurDate = Arrays.asList(-2);
    public static void main(String[] args) {

        Date date = new Date();
        date.setTime(7997979708676786L);
        int day = date.getDay();
        System.out.println(day);
        int intervalDays = getIntervalDays(new Date(), new Date());
        System.out.println(intervalDays);

        System.out.println("--------------");
        System.out.println(excludeOccurDate);

    }

    public static int getIntervalDays(Date from,Date to){
        System.out.println("时间为："+truncate(to, Calendar.DATE).getTime());
        long interval = truncate(to, Calendar.DATE).getTime()-truncate(from, Calendar.DATE).getTime();
        int result = (int)(interval/(1000*3600*24));
        return result;
    }



}
class TestDuration{
    public static void main(String[] args) {
        testDateUtils();
    }

    public static void testDateUtils(){
        long timeLong = randomLongId();
        System.out.println("timeLong = " + timeLong);
        Date date = addTime(Duration.ofMillis(timeLong));
        System.out.println("date = " + DateUtil.getDateString(date));

        Date dateUtil = DateUtil.getDateUtil(new Date());
        String dateString = DateUtil.getDateString(dateUtil);
        System.out.println("dateString = " + dateString);
        Date dateNow = new Date();
        // 最小账单日-180天
        Date minMustPayDate = DateUtils.addDays(dateNow,-310);
        Date maxMustPayDate = DateUtils.addDays(dateNow,-180);
        System.out.println("minMPayDate = " +  DateUtil.getDateString(DateUtil.getDateUtil(minMustPayDate)));
        System.out.println("maxMPayDate = " +  DateUtil.getDateString(DateUtil.getDateUtil(maxMustPayDate)));
        List<Date> mustPayDates = DateUtils.getBetweenDates(minMustPayDate, maxMustPayDate);
        for (Date mustPayDate : mustPayDates) {
            String dateString1 = DateUtil.getDateString(DateUtil.getDateUtil(mustPayDate));
            System.out.println("dateString1 = " + dateString1);
        }

    }

    public static Date addTime(Duration duration) {
        return new Date(System.currentTimeMillis() + duration.toMillis());
    }

    public static Long randomLongId() {
        return RandomUtil.randomLong(0, Long.MAX_VALUE);
    }
}





